package com.liu.sunnyday.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.liu.sunnyday.constant.MessageConstant;
import com.liu.sunnyday.entity.Result;
import com.liu.sunnyday.pojo.Setmeal;
import com.liu.sunnyday.service.SetmealService;
import com.liu.sunnyday.utils.QiNiuUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * chance！Time
 *
 * @author liuqian
 * @date 2022-06-24 12:44
 * *
 */

@RestController
@RequestMapping("/setmealm")
public class SetmealMobileController {
    @Reference
    private SetmealService setmealService;

    /**
     * 查询所有
     */
    @GetMapping("/getSetmeal")
    public Result getSetmeal() {
        // 查询所有的套餐
        List<Setmeal> list = setmealService.findAll();
        // 套餐里有图片有全路径吗? 拼接全路径
        list.forEach(s -> {
            s.setImg(QiNiuUtils.DOMAIN + s.getImg());
            System.out.println(s.getImg());
        });

        System.out.println();
        return new Result(true, MessageConstant.GET_SETMEAL_LIST_SUCCESS, list);
    }

    @GetMapping("findById")
    public Result findById(Integer id) {
        Setmeal setmeal = setmealService.findById(id);
        setmeal.setImg(QiNiuUtils.DOMAIN + setmeal.getImg());
        return new Result(true, MessageConstant.QUERY_CHECKITEM_SUCCESS, setmeal);
    }

    @GetMapping("/findDetailById")
    public Result findDetailById(Integer id) {
        //根据套餐id多表联查详情信息，所有需要信息（建议全查，以免后期调整）
        Setmeal setmeal = setmealService.findDetailById(id);
        //将img的格式拼接以方便去七牛云拿
        setmeal.setImg(QiNiuUtils.DOMAIN + setmeal.getImg());
        return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, setmeal);
    }
}
